# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libblocksruntime
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.4.1
pkgrel=1
pkgdesc='compiler-rt Blocks runtime library for Clang (mingw-w64)'
arch=('any')
url="https://compiler-rt.llvm.org"
license=("custom:University of Illinois" "MIT")
depends=("${MINGW_PACKAGE_PREFIX}-clang")
source=("http://http.debian.net/debian/pool/main/libb/${_realname}/${_realname}_${pkgver}.orig.tar.gz"
        "0001-libblocksruntime-0.4.1-fix-shared-installation.patch")
sha256sums=('7807e18d7d6cabd90f77c8b8a8ebd472516fa4ed6a02df82e0c33b1c5e112abc'
            '73cd40b3d8da2adf03ba85ba9a615d19512289bfc71dafb1f6240bb61540b24d')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-libblocksruntime-0.4.1-fix-shared-installation.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
